package com.leetcode.algorithm.y22.m06;

/**
 * 413. 等差数列划分
 * 
 * https://leetcode.cn/problems/arithmetic-slices/
 * 
 * @author jie.deng
 *
 */
class Question0413Solution01 {

	public int numberOfArithmeticSlices(int[] nums) {
		int len = nums.length;
		// dp[i]表示nums[j...i](j>=0，以nums[i]结尾)中等差数组的个数
		int[] dp = new int[len];
		for (int i = 2; i < len; i++) {
			if (nums[i] - nums[i - 1] == nums[i - 1] - nums[i - 2]) {
				dp[i] = dp[i - 1] + 1;
			}
		}
		int cnt = 0;
		for (int i = 2; i < len; i++) {
			cnt += dp[i];
		}
		return cnt;
	}

}